package com.lechuang.xiaoxiao.base;

import android.app.Activity;
import android.app.Application;

import com.alibaba.baichuan.android.trade.AlibcTradeSDK;
import com.alibaba.baichuan.android.trade.callback.AlibcTradeInitCallback;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/18.
 */

public class MyApplication extends Application {
    public static MyApplication myApplaction=null;
    //单例模式中获取唯一的MyApplication实例
    private List<Activity> activityList = new LinkedList<Activity>();
/**
 *  @author li
 *  邮箱：961567115@qq.com
 *  @time 2017/9/26  11:22
 *  @describe 初始化百川
 */

    @Override
    public void onCreate() {
        super.onCreate();
        myApplaction=this;
        AlibcTradeSDK.asyncInit(this, new AlibcTradeInitCallback() {
            @Override
            public void onSuccess() {
                //初始化成功，设置相关的全局配置参数
                // 是否使用支付宝
                AlibcTradeSDK.setShouldUseAlipay(true);
                // 设置是否使用同步淘客打点
                AlibcTradeSDK.setSyncForTaoke(true);
                // 是否走强制H5的逻辑，为true时全部页面均为H5打开
                AlibcTradeSDK.setForceH5(true);

            }

            @Override
            public void onFailure(int code, String msg) {
                //初始化失败，可以根据code和msg判断失败原因，详情参见错误说明
            }
        });


    }


    public static MyApplication getInstance() {
        if (null == myApplaction) {
            myApplaction = new MyApplication();
        }
        return myApplaction;
    }

    //添加Activity到容器中
    public void addActivity(Activity activity) {
        activityList.add(activity);
    }

    //遍历所有Activity并finish
    public void exit() {
        for (Activity activity : activityList) {
            activity.finish();
        }
    }

}
